package com.hqd.ch03.v23.aop.framework.aspectj;

import com.hqd.ch03.v23.aop.Pointcut;
import com.hqd.ch03.v23.aop.PointcutAdvisor;
import com.hqd.ch03.v23.aopalliance.aop.Advice;
import com.hqd.ch03.v23.core.Ordered;

public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered {
    /**
     * 切点
     */
    private Pointcut pointcut;
    /**
     * 通知
     */
    private AbstractAspectJAdvice advice;
    private Integer order;

    public AspectJPointcutAdvisor() {

    }

    public AspectJPointcutAdvisor(AbstractAspectJAdvice advice) {
        this.setAdvice(advice);
    }

    @Override
    public int getOrder() {
        if (this.order != null) {
            return this.order;
        } else {
            return this.advice.getOrder();
        }
    }

    public void setOrder(int order) {
        this.order = order;
    }

    @Override
    public Advice getAdvice() {
        return this.advice;
    }

    public void setAdvice(Advice advice) {
        this.advice = (AbstractAspectJAdvice) advice;
        this.pointcut = this.advice.getPointcut();
    }

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    public String getAspectName() {
        return this.advice.getAspectName();
    }
}
